package com.itheima.controller.mobile;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    @Qualifier("setmealServiceImpl")
    private SetmealService setmealService;


    /**
     * 查询所有套餐
     * @return
     */
    @PostMapping("/getSetmeal")
    public Result findAll() {
        List<Setmeal> result = setmealService.findAll();
        if (result != null && !result.isEmpty()) {
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, result);
        } else {
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @PostMapping("/findById")
    public Result findById(Integer id){
        Setmeal setmeal = setmealService.findById(id);
        if(setmeal != null){
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        }
        else {
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
